﻿using System;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Trust.Casas.Web.Extentions
{
    public static class MvcHtmlStringExtentions
    {
        public static IHtmlString CreateLineIf(Func<bool> predicate, string valueFormat, params object[] parameters)
        {
            if (predicate())
                return MvcHtmlStringExtentions.CreateLine(valueFormat, parameters);
            
            return MvcHtmlString.Create(string.Empty);
        }

        public static IHtmlString CreateLine(string valueFormat, params object[] parameters)
        {
            return MvcHtmlString.Create(string.Format(valueFormat, parameters) + Environment.NewLine);
        }
    }

    public static class HtmlHelperExtentions
    {
        public static IHtmlString ToJson(this HtmlHelper html, object obj)
        {
            return html.Raw(System.Web.Helpers.Json.Encode(obj));
        }
    }
}